package com.s64.ch08.modules.mq;

import com.s64.ch08.entity.User;
import com.s64.ch08.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MqConsumer {
    @Autowired
    private IUserService userService;

    @RabbitListener(queues = "queue1")
//    @SneakyThrows
    public void handler(User user) {
        log.info("收到用户创建消息");
//        Thread.sleep(2000);
        userService.save(user);
        log.info("创建用户成功！");
    }

}
